package com.example.siyun.controller.staticscontroller;

import com.example.siyun.pojo.*;
import com.example.siyun.service.statisticsservice.CoustaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
 * 统计列表
 * @author：刘宝龙
 *@Date: 2022-10-12
 * */
@RestController
public class CourseStatisticController {
    /*
     * 统计列表
     * @author：刘宝龙
     *@Date: 2022-10-12
     * */
    @Autowired
    private CoustaService coustaServiceimpl;

    /**
     * 课程收藏统计
     * @param number
     * @return
     */
    @RequestMapping("/primary/selectcourse")
    public Map<String,Object> del(Integer number){
        Map<String, Object> map = new HashMap<>();
        List<Integer> aa=coustaServiceimpl.getCourseListId();
        List<String> coursename=coustaServiceimpl.getCourseName(aa);
        List<Integer> coursecount=new ArrayList<>();
        List<CourseSatis> courseSatis=new ArrayList<>();
        List<Piechart> piecharts=new ArrayList<>();
        for (String a: coursename) {
            CourseSatis courseSatis1=new CourseSatis();
            int count= coustaServiceimpl.getCourseStacount(a);
            Piechart piechart=new Piechart();
            courseSatis1.setType(a);
            piechart.setValue(count);
            piechart.setName(a);
            coursecount.add(count);
            courseSatis1.setCount(count);
            courseSatis.add(courseSatis1);
            piecharts.add(piechart);
        }
        map.put("state",200);
        map.put("code",0);
        map.put("data",courseSatis);
        map.put("piedata",piecharts);
        map.put("coursename",coursename);
        map.put("coursecount",coursecount);
        return map;
    }

    /**
     * 课程点赞统计
     * @return
     */
    @RequestMapping("/primary/like")
    public Map<String,Object> like(){
        Map<String, Object> map = new HashMap<>();
        //是表格的数据
        List<CourseSatis> courseSatis=new ArrayList<>();
        //是柱状和折线图的横轴
        List<String> coursename=new ArrayList<>();
        //是柱状和折线图的纵轴
        List<Integer> coursecount=new ArrayList<>();
        //是扇形图的数据
        List<Piechart> piecharts=new ArrayList<>();

        List<CourseTable> getcourselike = coustaServiceimpl.getCourseLike();
        for (CourseTable a: getcourselike) {
            Piechart piechart=new Piechart();
            CourseSatis courseSatis1=new CourseSatis();
            String name=a.getName();
            courseSatis1.setType(name);
            coursename.add(name);
            piechart.setName(name);
            int getcoursecount = coustaServiceimpl.getCourseCount(name);
            piechart.setValue(getcoursecount);
            courseSatis1.setCount(getcoursecount);
            coursecount.add(getcoursecount);
            courseSatis.add(courseSatis1);
            piecharts.add(piechart);
        }
        map.put("state",200);
        map.put("code",0);
        map.put("piedata",piecharts);
        map.put("data",courseSatis);
        map.put("coursename",coursename);
        map.put("coursecount",coursecount);
        return map;
    }

    /**
     * 商品点赞统计
     * @return
     */
    @RequestMapping("/primary/Productlike")
    public Map<String,Object> productLike(){
        Map<String, Object> map = new HashMap<>();
        //是表格的数据
        List<CourseSatis> courseSatis=new ArrayList<>();
        //是柱状和折线图的横轴
        List<String> coursename=new ArrayList<>();
        //是柱状和折线图的纵轴
        List<Integer> coursecount=new ArrayList<>();
        //是扇形图的数据
        List<Piechart> piecharts=new ArrayList<>();

        List<JsProduct> getcourselike = coustaServiceimpl.getProductLike();
        for (JsProduct a: getcourselike) {
            Piechart piechart=new Piechart();
            CourseSatis courseSatis1=new CourseSatis();
            String name=a.getProductName();
            courseSatis1.setType(name);
            coursename.add(name);
            piechart.setName(name);
            int getcoursecount = coustaServiceimpl.getProductCount(name);
            piechart.setValue(getcoursecount);
            courseSatis1.setCount(getcoursecount);
            coursecount.add(getcoursecount);
            courseSatis.add(courseSatis1);
            piecharts.add(piechart);
        }
        map.put("state",200);
        map.put("code",0);
        map.put("piedata",piecharts);
        map.put("data",courseSatis);
        map.put("coursename",coursename);
        map.put("coursecount",coursecount);
        return map;
    }

    /**
     * 人员统计
     * @return
     */
    @RequestMapping("/primary/User")
    public Map<String,Object> user(){
        Map<String, Object> map = new HashMap<>();
        //是表格的数据
        List<CourseSatis> courseSatis=new ArrayList<>();
        //是柱状和折线图的横轴
        List<String> coursename=new ArrayList<>();
        //是柱状和折线图的纵轴
        List<Integer> coursecount=new ArrayList<>();
        //是扇形图的数据
        List<Piechart> piecharts=new ArrayList<>();

        List<UserList> getcourselike = coustaServiceimpl.getUser();
        for (UserList a: getcourselike) {
            Piechart piechart=new Piechart();
            CourseSatis courseSatis1=new CourseSatis();
            String name=a.getUserAccount();
            courseSatis1.setType(name);
            coursename.add(name);
            piechart.setName(name);
            int getcoursecount = coustaServiceimpl.getUserCount(name);
            piechart.setValue(getcoursecount);
            courseSatis1.setCount(getcoursecount);
            coursecount.add(getcoursecount);
            courseSatis.add(courseSatis1);
            piecharts.add(piechart);
        }
        map.put("state",200);
        map.put("code",0);
        map.put("piedata",piecharts);
        map.put("data",courseSatis);
        map.put("coursename",coursename);
        map.put("coursecount",coursecount);
        return map;
    }

    /**
     * 商品购买次数统计
     * @return
     */
    @RequestMapping("/primary/Productcount")
    public Map<String,Object> productcount(){
        Map<String, Object> map = new HashMap<>();
        //是表格的数据
        List<CourseSatis> courseSatis=new ArrayList<>();
        //是柱状和折线图的横轴
        List<String> coursename=new ArrayList<>();
        //是柱状和折线图的纵轴
        List<Integer> coursecount=new ArrayList<>();
        //是扇形图的数据
        List<Piechart> piecharts=new ArrayList<>();

        List<JsProduct> getcourselike = coustaServiceimpl.getProductGouMai();
        for (JsProduct a: getcourselike) {
            Piechart piechart=new Piechart();
            CourseSatis courseSatis1=new CourseSatis();
            String name=a.getProductName();
            courseSatis1.setType(name);
            coursename.add(name);
            piechart.setName(name);
            System.out.println(name);
            Integer getcoursecount = coustaServiceimpl.getProductCiShu(name);
            if(getcoursecount !=null){
                piechart.setValue(getcoursecount);
                courseSatis1.setCount(getcoursecount);
            }

            coursecount.add(getcoursecount);
            courseSatis.add(courseSatis1);
            piecharts.add(piechart);
        }
        map.put("state",200);
        map.put("code",0);
        map.put("piedata",piecharts);
        map.put("data",courseSatis);
        map.put("coursename",coursename);
        map.put("coursecount",coursecount);
        return map;
    }


    /**
     * 课程购买次数统计
     * @return
     */
    @RequestMapping("/primary/keChengTongJi")
    public Map<String,Object> keChengCount(){
        Map<String, Object> map = new HashMap<>();
        //是表格的数据
        List<CourseSatis> courseSatis=new ArrayList<>();
        //是柱状和折线图的横轴
        List<String> coursename=new ArrayList<>();
        //是柱状和折线图的纵轴
        List<Integer> coursecount=new ArrayList<>();
        //是扇形图的数据
        List<Piechart> piecharts=new ArrayList<>();

        List<CourseTable> getcourselike = coustaServiceimpl.keChengGouMai();
        for (CourseTable a: getcourselike) {
            Piechart piechart=new Piechart();
            CourseSatis courseSatis1=new CourseSatis();
            String name=a.getName();
            courseSatis1.setType(name);
            coursename.add(name);
            piechart.setName(name);
            System.out.println(name);
            Integer getcoursecount = coustaServiceimpl.keChengCiShu(name);
            if(getcoursecount !=null){
                piechart.setValue(getcoursecount);
                courseSatis1.setCount(getcoursecount);
            }

            coursecount.add(getcoursecount);
            courseSatis.add(courseSatis1);
            piecharts.add(piechart);
        }
        map.put("state",200);
        map.put("code",0);
        map.put("piedata",piecharts);
        map.put("data",courseSatis);
        map.put("coursename",coursename);
        map.put("coursecount",coursecount);
        return map;
    }

}
